import axios from 'axios'
import store from '../store'
import { Message } from 'element-ui'
 
// 创建axios实例
const request2 = axios.create({
  baseURL: 'http://60.188.49.69:8099/prod-api/thinglinks-modules-screen',
  // baseURL:'http://192.168.43.99:10527',
  // baseURL: 'http://192.168.43.99:10527',
  timeout: 15000
})

request2.interceptors.request.use(
  function (config) {
    const token = store.getters.token
    if (token) {
      config.headers.Authorization = `Bearer ${token}`
    }
    // 在发送请求之前做些什么
    return config
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  }
)

// 添加响应拦截器
request2.interceptors.response.use(async function (response) {
  // 默认json格式
  // 在每次响应数据返回的时候解构
  console.log(response)
  const { msg, status } = response

  if (status === 200) {
    return response
  } else {
    console.log(response)
    Message.error(msg)
  }
})

// 导出axios实例
export default request2
